<?php
/**
 * Created by PhpStorm.
 * User: xiaofang
 * Date: 2020/12/12
 * Time: 12:32
 */

namespace app\admin\model;


use think\Db;
use think\Exception;
use think\Model;

class NydControlDev extends Model
{

    public function getDevList($gw_id)
    {
        return Db::name("nyd_control_dev")->where("gateway_id",$gw_id)
            ->field("control_id,is_open")
            ->where("is_del",'1')
            ->select();
    }

    /**
     * @param $gw_id
     * @param $is_open
     * @param $control_id
     * @return array
     */
    public function setDevStatus($gw_id,$is_open,$control_id)
    {
        try{
            Db::name("nyd_control_dev")
                ->where("gateway_id",$gw_id)
                ->where("control_id",$control_id)
                ->update([
                    'is_open'   =>  $is_open,
                ]);

        }catch (Exception $exception){
            return ret_com(0,'error '.$exception->getMessage());
        }

        return ret_com();
    }
}